package com.xindaoapp.happypet.ui;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;

import com.xindaoapp.happypet.R;
import com.xindaoapp.happypet.adapter.CommonViewPagerAdapter;
import com.xindaoapp.happypet.fragments.MyAttentionFragment;
import com.xindaoapp.happypet.fragments.MyFansFragment;
import com.xindaoapp.happypet.utils.Constants;

/**
 * @好友，发帖页面
 * 
 * @author chenghao
 * 
 */
public class QuoteFriendActivity extends BaseActivity implements OnClickListener {
    private ViewPager vViewPager;

    @Override
    protected int getContentViewResId() {
        return R.layout.activity_quote_friend;
    }

    @Override
    protected void initViews() {
        super.initViews();
        vViewPager = (ViewPager) findViewById(R.id.viewpager);
        Fragment[] fragments =
                new Fragment[] {
                        MyAttentionFragment.newInstance(
                                getIntent().getStringExtra(Constants.KEY_GROUP_FID), true),
                        MyFansFragment.newInstance(true)};
        View[] tabViews =
                new View[] {findViewById(R.id.tab_left_view), findViewById(R.id.tab_right_view)};
        CommonViewPagerAdapter adapter =
                new CommonViewPagerAdapter(getSupportFragmentManager(), fragments, tabViews);
        for (int i = 0; i < tabViews.length; i++) {
            final int temp = i;
            tabViews[i].setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    vViewPager.setCurrentItem(temp);
                }
            });
        }
        vViewPager.setAdapter(adapter);
        vViewPager.setOffscreenPageLimit(3);
        vViewPager.setOnPageChangeListener(adapter);
    }

    @Override
    protected void initEvents() {
        super.initEvents();
        findViewById(R.id.top_bar_left_imageview).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.top_bar_left_imageview:
                finish();
                break;
            default:
                break;
        }
    }

    @Override
    protected OnClickListener getLeftViewClickListener() {
        return new OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
            }
        };
    }

    @Override
    protected int getTopBarLeftImageViewRes() {
        return R.drawable.top_bar_back;
    }

}
